package com.dms.modules.community.service;

import com.dms.common.security.SecurityUtils;
import com.dms.modules.community.entity.CommunityPost;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("communitySecurityService")
@RequiredArgsConstructor
public class CommunitySecurityService {

    private final CommunityPostService postService;

    /**
     * 检查当前用户是否是帖子的所有者
     *
     * @param postId 帖子ID
     * @return true如果是所有者，false如果不是
     */
    @Transactional(readOnly = true)
    public boolean isPostOwner(Long postId) {
        try {
            CommunityPost post = postService.getById(postId);
            if (post == null) {
                return false;
            }
            Long currentUserId = SecurityUtils.getCurrentUserId();
            return post.getUserId().equals(currentUserId);
        } catch (Exception e) {
            return false;
        }
    }
} 